package yangan.utils;


import app.nbdevices.utils.ConvertUtil;
import yangan.modle.codecModel.YanganCycleReport;
import yangan.modle.codecModel.YanganEventReport;
import yangan.modle.revModle.RevYanganCycleData;
import yangan.modle.revModle.RevYanganEventData;

public class YanganDataDecode {

    public static YanganCycleReport yanganCycleDataDecode(RevYanganCycleData revYanganCycle){
        byte[] res= ConvertUtil.getBase64Codec().decode(revYanganCycle.getReportData());
        YanganCycleReport yanganCycleReport =new YanganCycleReport();
        yanganCycleReport.setStateCode(ConvertUtil.arraySub(res,0,1));
        yanganCycleReport.setVoltage(res[2]);
        yanganCycleReport.setSignal(res[3]);
        yanganCycleReport.setNBNumber(ConvertUtil.arraySub(res,4,8));
        return yanganCycleReport;
    }
    public static YanganEventReport yanganEventDataDecode(RevYanganEventData revYanganEventData){
        byte[] res=ConvertUtil.getBase64Codec().decode(revYanganEventData.getReportData());
        YanganEventReport yanganEventReport=new YanganEventReport();
        yanganEventReport.setStateCode(ConvertUtil.arraySub(res,0,1));
        yanganEventReport.setVoltage(res[2]);
        yanganEventReport.setSignal(res[3]);
        yanganEventReport.setNBNumber(ConvertUtil.arraySub(res,4,8));
        yanganEventReport.setProtectNum(res[10]);
        byte[] spare=new byte[10];
        spare[0]=res[9];
        byte[] tems=ConvertUtil.arraySub(res,11,19);
       for(int i=0;i<tems.length;i++){
           spare[i+1]=tems[i];
       }
       yanganEventReport.setSpare(spare);
        return yanganEventReport;
    }
}
